<template>
  <div class="iframe">
    <iframe style="border:none" class="h-full w-full" :src="iframeUrl" ></iframe>
  </div>
</template>
<script>
import dapProjectService from '@/api/dapProjectService'
import BtnEventHelpFn from '@/api/btnEventHelpUtil'
import projectService from '@/api/projectService'

export default {
    name: 'Iframe',
    data () {
        return {
            iframeUrl: '',
            searchTableHeight: 0,
            searchTableWidth: 0
        }
    },
     watch: {
        $route: function () {
        // 监听路由变化
            this.iframeUrl = this.$route.meta.pathUrl
        }
    },
    created () {
        this.iframeUrl = this.$route.meta.pathUrl
    },
    mounted () {
      this.btnEventHelpUtil = new BtnEventHelpFn(this)
      const _this = this
      window.onmessage = function ($event) {
        console.log($event)
        // var data = JSON.parse($event.data)
        if ($event.data.type && event.data.type === 'createSWXZProject') {
          // const projectCode = $event.data.data.projectCode || null
          _this.createProject($event.data.data.name, $event.data.data)
        }
      }
      window.onresize = () => {
          this.widthHeight() // 自适应高宽度
      }
      this.$nextTick(function () {
          this.widthHeight()
      })
    },
    methods: {
      createProject (xmmc, data) {
        dapProjectService.getCreateProcessList(null, '智慧选址').then((d) => {
          var formatData = this.btnEventHelpUtil.formatData(d)
          if (formatData) {
            formatData.forEach(item => {
              if (item.name === '智慧选址') {
                const initData = {
                  // initProjectCode: 0,
                  bz_projectcase: [{
                    xmmc: xmmc,
                    xzqhmc: data.properties.xzqmc
                  }],
                  bz_zh_xmjbqk: [{
                    ydxz: data.properties.ydflmc,
                    ydmj: data.properties.mj
                  }]
                }
                // if (projectcode) {
                //   initData.bz_projectcase[0].projectcode = projectcode
                // }
                this.btnEventHelpUtil.createYtgzProject(item.children[0], initData, null, false, function (projectId) {
                  const gisData = {
                    geometry: data.geometry.geometry,
                    XZQMC: data.properties.xzqmc,
                    YDXZ: data.properties.ydflmc,
                    YDMJ: data.properties.mj
                  }
                  projectService.createGisProject({ projectId: projectId }, gisData).then((rs) => {
                    console.log(rs)
                  })
                })
              }
            })
          }
        })
      },
      widthHeight () {
          this.searchTableHeight = window.innerHeight - 70
          this.searchTableWidth = window.innerWidth
      }
    }
}
</script>
<style lang="less">
.iframe{
  height: 100%;
}
</style>
